import { createSlice,createAsyncThunk  } from '@reduxjs/toolkit';
import {getById} from '../../services/student';

export const fetchStudent = createAsyncThunk('student/fetchStudent',async (id) => {
    let {data} = await getById(id);
    return data;
});

const studentSlice = createSlice({
    name: "student",
    initialState:{
        updateVisible:false,
        student:{}
    },
    reducers:{
        setUpdateVisible(state,action){
            state.updateVisible = action.payload;
        }
      
    },
    extraReducers(builder) {
        builder.addCase(fetchStudent.fulfilled, (state, action) => {
            state.student = action.payload;
        })
    }
});
export const {setUpdateVisible} = studentSlice.actions;
export default studentSlice.reducer;